import { Viewer, Cartesian3, Math } from "cesium";
import "cesium/Build/Cesium/Widgets/widgets.css";

import { loadBaseMap } from "./loaderBaseMap";

import { load_terrain } from "./load_terrain";

class NzCzm {
  constructor() {
    this.viewer = null;
  }

  init(target) {
    this.viewer = new Viewer(target, {
      geocoder: false,
      animation: false,
      timeline: false,
      infoBox: false,
      homeButton: false,
      baseLayerPicker: false,
      sceneModePicker: false,
      navigationHelpButton: false,
      fullscreenButton: false,
    });

    this.viewer.cesiumWidget.creditContainer.style.display = "none"; // 隐藏Logo，水印
    this.viewer.imageryLayers.removeAll();

    this.selectBaseMap("tdt_img");

    load_terrain(this.viewer, "none");

    this.home();
  }

  selectBaseMap = (type) => {
    loadBaseMap(this.viewer, type);
  };

  selectTerrain = (type) => {
    load_terrain(this.viewer, type);
  };

  terrain_exaggerate = (exag) => {
    this.viewer.scene.verticalExaggeration = exag;
  };

  home = () => {
    setTimeout(() => {
      this.viewer.camera.flyTo({
        destination: Cartesian3.fromDegrees(103.84, 31.15, 8000000),
        orientation: {
          heading: Math.toRadians(0),
          pitch: Math.toRadians(-89.74026687972041),
          roll: Math.toRadians(0),
        },
        complete: function callback() {
          // 定位完成之后的回调函数
        },
      });
    }, 100);
  };
}

export default NzCzm;
